package business.inhospitalqc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;

import static common.Login.login;

public class QcBatchList {
    Logger log = Logger.getLogger(QcBatchList.class);
    public static final String system = "env.properties";
    Data data = login();


    public JSONArray Getbatchlist (int i) throws FileNotFoundException, ConfigurationException, YamlException {
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml= YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("initiatorId", data.getUserId());
        json.put("types",  yaml.getDatas().get(i).get("types"));   //1=copd，2=aecopd 检测表，3=指标检测图
        json.put("makeFlag",  yaml.getDatas().get(i).get("makeFlag"));
        json.put("page",  yaml.getDatas().get(i).get("page"));
        json.put("size",  yaml.getDatas().get(i).get("size"));
        json.put("diseaseCode",  yaml.getDatas().get(i).get("diseaseCode"));
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", yaml.getUri());
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        JSONObject jsonObject = JSON.parseObject(jsonStr);
        JSONObject obj1 = jsonObject.getJSONObject("responseData");
        JSONArray jsonArray=obj1.getJSONArray("content");
        return jsonArray;
    }



    public static void main(String[] args) throws FileNotFoundException, ConfigurationException, YamlException {
        QcBatchList bt=new QcBatchList();
        JSONArray jsonArray=bt.Getbatchlist(0);
        System.out.println(jsonArray.toString());
    }

}
